package com.cit.draw.http;

import java.util.Arrays;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.cit.draw.messages.TestMessage;

//The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {

	// The Java method will process HTTP GET requests
	@GET
	// The Java method will produce content identified by the MIME Media
	// type "text/plain"
	@Produces("text/plain")
	public String getClichedMessage() {
		// Return some cliched textual content
		return "Hello World";
	}
	@POST
	@Path("/json")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public String testPostMethodWithJson(TestMessage message){
		return Arrays.toString(message.getFields());
		
	}
	
	@GET
	@Path("/json/get")
	@Produces(MediaType.APPLICATION_JSON)
	public Response testGetMethodWithJson(){
		TestMessage message = new TestMessage();
		message.setTopic("test");
		String[] fields = {"ok"};
		message.setFields(fields);
		return Response.ok(message).build();
	}
}